package com.mhkj.base.busiType.controller;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mhkj.base.busiType.entity.BusinessType;
import com.mhkj.base.busiType.service.BusinessTypeService;
import com.mics.core.common.componet.Pagination;
import com.mics.core.common.componet.ResponseMessage;
import com.mics.core.common.componet.SimpleCode;
import com.mics.core.system.base.controller.BaseController;

/**
 * 业务类型维护接口
 * @author ypx
 * @date 2018年7月2日
 * @version 1.0
 */
@Controller
@RequestMapping(value = "/businessType")
public class BusinessTypeController extends BaseController<BusinessType> {
	@Resource
	private BusinessTypeService businessTypeService;
	@Resource
	private SimpleCode simpleCode;

	/**
	 * 添加业务类型
	 */
	@RequestMapping(value = "/add", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage save(BusinessType t) {
		String code = simpleCode.generatorSimpleCode(BusinessType.class, "typeCoding");
		t.setTypeCoding(code);
		String message = businessTypeService.save(t);
		if("ok".equals(message)){
			return ResponseMessage.createMessage(true, "添加业务类型成功");
		}else{
			return ResponseMessage.createMessage(false, message);
		}
	}

	/**
	 * 修改业务类型
	 */
	@RequestMapping(value = "/edit", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage edit(BusinessType t) {
		String message = businessTypeService.edit(t);
		if("ok".equals(message)){
			return ResponseMessage.createMessage(true, "修改业务类型成功");
		}else{
			return ResponseMessage.createMessage(false, message);
		}
	}

	/**
	 * 删除业务类型
	 */
	@RequestMapping(value = "/del", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage del(BusinessType t) {
		String message = businessTypeService.del(t);
		if("ok".equals(message)){
			return ResponseMessage.createMessage(true, "删除业务类型成功");
		}else{
			return ResponseMessage.createMessage(false, message);
		}
	}

	/**
	 * 查询业务类型列表
	 */
	@RequestMapping(value = "/list", method = RequestMethod.POST)
	@ResponseBody
	public Pagination<BusinessType> list(BusinessType entity, Integer pageIndex, Integer pageSize) {
		Pagination<BusinessType> findPage = businessTypeService.findPage(entity, pageIndex, pageSize);
		return findPage;

	}

	/**
	 * 根据Id查询业务类型
	 */
	@RequestMapping(value = "/info", method = RequestMethod.POST)
	@ResponseBody
	public BusinessType info(Long id) {
		BusinessType businessType = businessTypeService.getById(id);
		return businessType;
	}

	
	/**
	 * 查询所有业务类型
	 * @author mics
	 * @date 2018年8月30日
	 * @version 1.0
	 */
	@RequestMapping("/listAll")
	@ResponseBody
	public List<BusinessType> listAll(){
		List<BusinessType> businessTypes = businessTypeService.findAll();
		return businessTypes;
	}

}
